package com.nicho.service;

import java.util.ArrayList;

import com.nicho.dao.TeacherDAO;
import com.nicho.pojo.Course;
import com.nicho.pojo.Student;
import com.nicho.pojo.Teacher;

/*
 * @Author: 姜东浩
 * @Date: 2021-11-12 08:35:09
 * @LastEditors: 姜东浩
 * @LastEditTime: 2021-11-12 13:49:56
 * @Description: 教师业务类
 */
public class TeacherService {

    TeacherDAO teacherDAO = new TeacherDAO();

    /**
     * @description: 教师登录验证
     * @param {Teacher} teacher
     * @return 登陆成功返回教师对象，登陆失败返回null
     * @author: 姜东浩
     */    
    public Teacher teacherLogin(Teacher teacher) {

        return teacherDAO.teacherLogin(teacher);

    }

    /**
     * @description: 修改自己的密码
     * @param {String} newPassword
     * @return 修改密码操作结束后的对应提示信息
     * @author: 姜东浩
     */
    public String updatePassword(String newPassword) {

        if (teacherDAO.updatePassword(newPassword) == 1) {
            return "修改成功";
        } else {
            return "修改失败";
        }

    }

    /**
     * @description: 获取此教师管理的学生集合
     * @return 管理的学生集合或null
     * @author: 姜东浩
     */    
    public ArrayList<Student> getMyStudentList() {

        return teacherDAO.getMyStudentList();

    }

    /**
     * @description: （全部信息）打印此教师管理的学生集合
     * @param {ArrayList<Student>} myStudentList
     * @author: 姜东浩
     */     
    public void printMyStudentListAM(ArrayList<Student> myStudentList) {

        teacherDAO.printMyStudentListAM(myStudentList);
        
    }

     /**
     * @description: （简单打印）打印此教师管理的学生集合
     * @param {ArrayList<Student>} myStudentList
     * @author: 姜东浩
     */
    public void printMyStudentList(ArrayList<Student> myStudentList) {

        teacherDAO.printMyStudentList(myStudentList);

    }

    /**
     * @description: 通过学号查找此学生是不是自己教的学生
     * @param {String} studentId
     * @return 在自己的学生集合中返回学生对象，不在返回null
     * @author: 姜东浩
     */
    public Student existStudentById(String studentId) {

        return teacherDAO.existStudentById(studentId);

    }

    /**
     * @description: 获取自己所教课程信息
     * @return 如果在授课返回自己所教课程信息，否则返回无在授课程
     * @author: 姜东浩
     */    
    public String catMyTeachCourse(){

        if(teacherDAO.catMyTeachCourseId()!=null){
            Course course =  teacherDAO.getCourseById(teacherDAO.catMyTeachCourseId());
            return course.toStringT();
        }else{
            return "无在授课程";
        }

    }

    /**
     * @description: 登分
     * @param {String} courseId
     * @param {String} studentId
     * @param {Double} grade
     * @return 返回操作后提示信息
     * @author: 姜东浩
     */    
    public String addGrade(String studentId, Double grade){

        if(teacherDAO.setCourseToStuInSL(studentId,grade)==1){
            return "添加成功";
        }else{
            return "向学生表更新学生成绩失败";
        }
        
    }
    
}